<?php
namespace app\serveradv\service\adv;

use \app\manage\service\ApiBase;
use think\Validate;
/**
 * 广告位类
 * @author  蒋哲
 * 验证：
        添加或编辑时：
        [不需要验证的字段:''默认值]   [需要验证但不require的:' '默认,使其验证]   [必须require的字段:无需默认值]
        搜索时：
        可空，给予''默认值，跳过验证器即搜索值为空时，不验证，不搜索
 * 编辑类，传什么验什么
 */
class ApiAdvClassify extends ApiBase
{
    protected $addFields   = ["name"=>"", "app_id"=>"", "other_app_read"=>" ", "is_public"=>0, "action"=>"", "pid"=>0, "order"=>0, "description"=>" ", "status"=>"1", "add_user_id"=>""];
    protected $advValidate = 'app\serveradv\validate\AdvClassify';
    protected $advLogic    = '\app\serveradv\logic\AdvClassify';

    use \app\servergoods\traits\BaseCheckCate;

    // 广告位分类添加
    public function add()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData($this->addFields);
        $checkData = $this->_baseCheckCate($data, 'add', '', $this->advValidate, $this->advLogic);
        if ($checkData['status'] != SUCCESS_STATUS) {
            return $checkData;
        }
        return $this->logic($this->advLogic)->advClassifyAdd($data);
    }

    // 广告位分类编辑
    public function edit(): array
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $default = array_merge($this->addFields,['id'=>""]);
        $data = $this->issetReceiveData($default);
        $checkData = $this->_baseCheckCate($data, '', 'edit', $this->advValidate, $this->advLogic);
        if ($checkData['status'] != SUCCESS_STATUS) {
            return $checkData;
        }
        return $this->logic($this->advLogic)->advClassifyEdit($data);
    }

    // 启用某个分类广告位分类
    public function classifyEnable()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'advClassifyEnable','enable',$this->advValidate,$this->advLogic);
    }

    // 禁用某个分类广告位分类
    public function classifyDisable()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'advClassifyDisable','enable',$this->advValidate,$this->advLogic);
    }

    // 删除某个分类广告位分类
    public function classifyDelete()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'advClassifyDelete','enable',$this->advValidate,$this->advLogic);
    }

    // 获取某应用全部广告位分类列表 树状
    public function classifyList()
    {
        return $this->logic('\app\serveradv\logic\AdvClassify')->advClassifyList();
    }

    // 某一类广告位分类列表获取
    public function classifySomeList()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['pid'=>'','app_id'=>'']);
        return $this->stepRun($data,'advClassifySomeList','pid',$this->advValidate,$this->advLogic);
    }

    // 不同条件广告位分类列表获取 (分页)
    public function classifyCondition()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['keywords'=>'', 'page'=>'', 'listRows'=>'']);
        // keywords非必须，不验证
        return $this->logic('\app\serveradv\logic\AdvClassify')->advClassifyCondition($data);
    }

    // 获取某广告位分类详情
    public function classifyInfo()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->logic('\app\serveradv\logic\AdvClassify')->classifyInfo($data);
    }
}
